﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Tcvt.Packages
{
    public partial class MsbuildPropertiesUserControl : UserControl
    {
        private const string HELP_URL = "http://www.buddybuildtool.com/buddybuild/help/content/customproperties.htm";

        public delegate void RefreshGridFromServer();

        private RefreshGridFromServer _refreshGrid;

        public MsbuildPropertiesUserControl()
        {
            InitializeComponent();
            this.WaitPictureBox.Visible = false;
        }

        public DataGridView PropertiesGrid
        {
            get { return this.MsbuildPropertiesDataGridView; }
            protected set { }
        }

        public RefreshGridFromServer RefreshGrid
        {
            get
            {
                return _refreshGrid;
            }
            set
            {
                _refreshGrid = value;
            }
        }

        private void RestoreDefaultPropertiesButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(
                "This action will refresh the grid contents with the default values set on the server.\r\n" +
                "Any values you have set will be lost.\r\n\r\n" +
                "Do you want to continue?",
                Utils.MessageBoxTitle,
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);

            if (result == DialogResult.Yes)
            {
                if (_refreshGrid != null)
                {
                    this.WaitPictureBox.Image = Resources.loader_blue;
                    this.WaitPictureBox.Visible = true;
                    _refreshGrid();
                    this.WaitPictureBox.Visible = false;
                }
            }
        }

        private void HelpLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            // Redirect to the FAQ page on the website.
            Utils.LogMessage("MsbuildPropertiesUserControl::HelpLinkLabel_LinkClicked: Enter.");
            ProcessStartInfo processStartInfo = new ProcessStartInfo(HELP_URL);
            processStartInfo.CreateNoWindow = false;
            Process.Start(processStartInfo);
        }
    }
}
